<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../../static/js/jquery-1.11.0.js"></script>
    <title>提现</title>
    <style>
        .banner {
            width: 480px;
            height: 86vh;
            position: absolute;
            margin-top: 2vh;
            /*margin-left: 400px;*/
            right: 500px;
            background: rgba(255, 255, 255, 0.7);
            border-radius: 16px;
            text-align: center;
            /**/
            /*    内容超出时，打开滚动条*/
            overflow: auto;

        }

        #proName{
            width: 200px;
            height: 30px;
        }
        #fmoney{
            width: 178px;
            height: 26px;
        }


        .d1 {
            /*border: 1px solid red;*/
            width: 100%;
            /*!*    内容超出时，打开滚动条*!*/
            /*    overflow: auto;*/
        }
        .d1 >h1{
            margin-top: 70px;
        }

    </style>
    <script>

        $(function () {
            //切换验证码
            $("#code_img").click(function (){
                $("#code_img").attr("src","http://localhost:8080/kaptcha.jpg")
            })
            var u_id = $("#userid").text();
            var fmoney = $("#fmoney").val();
            var code = $("#code").val();
            var c_id=$("#proName").select().val();

            //选择银行卡下拉列表
            $.ajax({
                type: "post",
                url: "/BankServlet",
                dataType: "json",
                data: {
                    action: "findUid", u_id: u_id,
                },
                success: function (d) {
                    console.log(d)
                    if (d.code == 1) {
                        for (var i = 0; i < d.data.length; i++) {
                            var a = d.data[i].c_id;
                            var b = a.substring(a.length - 4);
                            $(".laySelect").append(" <option value='" + d.data[i].c_id + "'>" + d.data[i].c_account + "(" + b + ")</option>")
                        }
                    }
                }
            })
            //判断输入金额
            $("#fmoney").blur(function () {
                //正则表达式判断是否输入的值为大于零的正数
                var r = /^([1-9][0-9]*)+(.[0-9]{1,2})?$/;
                var fmoney = $("#fmoney").val();
                if (!r.test(fmoney)) {
                    $(".f").text("充值金额不能小于等于0")
                } else {
                    $(".f").text(" ")
                }
            })
          //回显app余额
            //var u_id = 3;
            $.ajax({
                url: "/BankServlet",
                type: "post",
                data: {
                    action:"findByUid",
                    u_id:u_id,
                },
                dataType: "json",
                success:function (d){
                    //成功
                    //渲染
                    console.log(d);
                    if (d.code==1){
                        //成功
                        $("#fmoney").attr("placeholder","app余额为："+d.data.u_balance)
                    }else {
                        $("#fmoney").text(" ")
                    }
                },
                error:function (){
                    //服务器出现异常时
                }
            })

            //提交事件
            $("#btn").click(function (){
                var u_id = $("#userid").text();
                var fmoney = $("#fmoney").val();
                var code = $("#code").val();
                var c_id=$("#proName").select().val();
                var apwd="";
                //输入框弹窗，获取到支付密码
                var p=prompt("请输入支付密码","");
                if(p!=""&&p!=null){
                    apwd=p;
                }
                $.ajax({
                    type: "post",
                    url: "/BankServlet",
                    dataType: "json",
                    data: {
                        action: "withdrawal",
                        c_id: c_id,
                        u_id: u_id,
                        fmoney:fmoney,
                        code:code,
                        apwd:apwd
                    },
                    success: function (d) {
                        if(d.code==1){
                            alert(d.msg);
                        }else{
                            alert(d.msg);
                        }
                    },
                    error: function () {
                        alert('Error');
                    }
                })
            })

        })


    </script>
</head>
<body>
<div class="banner">
    <div id="l_content" class="d1">
        <h1 >提现</h1>
        <br>
        <br>
        <br>
        <label>选择银行卡：</label>
        <select name="interest" id="proName" class="laySelect">
            <option value="-1">请选择</option>
        </select><br>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;<span style="color: brown" class="p"></span>
        <br><br><br>
        <label>输入提现金额:￥</label>
        <input type="text" name="fmoney" id="fmoney"  class="i"><br>
        &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; <span style="color: brown" class="f" id="fm"></span>
        <br><br><br>
        <label>验证码：</label>
        <input class="txt" type="text" name="code" style="width: 130px;height: 26px" id="code" placeholder="请输入验证码"/>
        <img id="code_img" alt="" src="http://localhost:8080/kaptcha.jpg"
             style="position: relative;left: 3px; top: 10px; width: 90px;height: 40px;"><br>
        <span style="color: brown" class="c"></span>
        <br>
        <br>
        <br>
        <input type="submit" value="确认提现" id="btn"
               style="width: 200px;height: 40px;position: relative;left: 0px;border-radius: 16px;"/>
    </div>
</div>

</body>
</html>